package shop.ibatis;

import java.io.IOException;
import java.io.Reader;
import java.util.List;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import JoinDAO.JoinVO;


public class LogInSqlMapper {
	 private static SqlSessionFactory LogInSqlMapper;
		static {
		   try {
		      Reader reader = Resources.getResourceAsReader("shop/ibatis/SqlMapConfig.xml");
		      LogInSqlMapper = new SqlSessionFactoryBuilder().build(reader);
		      reader.close(); 
		    } catch (IOException e) {
		      throw new RuntimeException("Something bad happened while building the SqlMapClient instance." + e, e);
		    }
		  }
		 
		public static int LogIn (JoinVO vo) {
			  
			  SqlSession session = LogInSqlMapper.openSession();
			  int count = (Integer) session.selectOne("LogIn", vo);
			  session.commit();
			
			  return count;
		  }
		public static JoinVO MemberInfo(JoinVO vo){
			SqlSession session = LogInSqlMapper.openSession();
			JoinVO joinVO =  (JoinVO) session.selectOne("MemberInfo", vo);
			session.commit();
			System.out.println(joinVO.toString());
			
			return joinVO;
		}
		
		public static JoinVO id_find_email(JoinVO vo ){
			try{
				SqlSession session = LogInSqlMapper.openSession();
				JoinVO joinVO =  (JoinVO) session.selectOne("id_find_email", vo);
				session.commit();
				System.out.println(joinVO.toString());
				
				return joinVO;
			}catch(Exception e){
				JoinVO v1 = new JoinVO();
				v1.setId("");
				return v1;
			}
			
		}
		
		public static JoinVO id_find_mobile(JoinVO vo ){
			try{
				SqlSession session = LogInSqlMapper.openSession();
				JoinVO joinVO =  (JoinVO) session.selectOne("id_find_mobile", vo);
				session.commit();
				System.out.println(joinVO.toString());
				
				return joinVO;
			}catch(Exception e){
				JoinVO v1 = new JoinVO();
				v1.setId("");
				return v1;
			}
			
		}
		
		public static JoinVO pw_find_email(JoinVO vo){
			try{
				SqlSession session = LogInSqlMapper.openSession();
				JoinVO joinVO =  (JoinVO) session.selectOne("pw_find_email", vo);
				session.commit();
				System.out.println(joinVO.toString());
				
				return joinVO;
			}catch(Exception e){
				JoinVO v1 = new JoinVO();
				v1.setPassword("");
				return v1;
			}
			
		}
		
		public static JoinVO pw_find_mobile(JoinVO vo){
			try{
				SqlSession session = LogInSqlMapper.openSession();
				JoinVO joinVO =  (JoinVO) session.selectOne("pw_find_mobile", vo);
				session.commit();
				System.out.println(joinVO.toString());
				
				return joinVO;
			}catch(Exception e){
				JoinVO v1 = new JoinVO();
				v1.setPassword("");
				return v1;
			}
			
		}
		
		
		
}